using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace hole.speedrungame
{
	public class UIGameOverSpeedRun : MonoBehaviour
	{
		public CanvasGroup background;

		public Text title;

		public Image progressionImage;

		public Text progressionText;

		public Text rewardText;

		public Transform[] scaleObjects;

		[Header("Continue")]
		public CanvasGroup continueGroup;

		public GameObject continueNormalObject;

		public GameObject continueRVObject;

		private float _score;

		private Color _color;

		public void Show()
		{
			base.gameObject.SetActive(value: true);
			title.rectTransform.anchoredPosition = new Vector2(0f, 130f);
			background.alpha = 0f;
			title.rectTransform.DOAnchorPosY(210f, 0.3f).SetDelay(0.5f);
			background.DOFade(1f, 0.3f).SetDelay(0.8f);
			float num = 1.3f;
			progressionImage.fillAmount = 0f;
			progressionImage.DOFillAmount(_score, 1f).SetEase(Ease.Linear).SetDelay(num);
			rewardText.text = "0";
			progressionText.text = "0.00%";
			float val = 0f;
			DOTween.To(() => val, delegate(float x)
			{
				for (int i = 0; i < GameManager.STAR_REWARD_THRESHOLD_TABLE.Length; i++)
				{
					if (val <= GameManager.STAR_REWARD_THRESHOLD_TABLE[i] && x > GameManager.STAR_REWARD_THRESHOLD_TABLE[i])
					{
						SetSelectedRewardSpeedRun(i);
					}
				}
				val = x;
			}, _score, 1f).SetEase(Ease.Linear).OnUpdate(delegate
			{
				if ((bool)progressionText)
				{
					progressionText.text = $"{val * 100f:0.00}%";
				}
			})
				.SetDelay(num);
			continueGroup.interactable = false;
			continueGroup.alpha = 0f;
			continueGroup.DOFade(1f, 0.2f).SetDelay(num + 0.5f).OnComplete(delegate
			{
				continueGroup.interactable = true;
			});
			//if (VoodooServiceLocator.Ads.IsRewardedVideoAvailable() && BaseGameManager.Instance.Reward > 1)
			//{
			//	continueNormalObject.SetActive(value: false);
			//	continueRVObject.SetActive(value: true);
			//}
			//else
			//{
			//	continueNormalObject.SetActive(value: true);
			//	continueRVObject.SetActive(value: false);
			//}
		}

		public void SetColor(Color color)
		{
			_color = color;
			progressionImage.color = color;
			progressionText.color = color;
		}

		public void SetScore(float score)
		{
			_score = score;
		}

		public void SetSelectedRewardSpeedRun(int index)
		{
			Transform transform = scaleObjects[GameManager.STAR_REWARD_THRESHOLD_TABLE.Length - index - 1].transform;
			Graphic[] componentsInChildren = transform.gameObject.GetComponentsInChildren<Graphic>();
			Graphic[] array = componentsInChildren;
			foreach (Graphic target in array)
			{
				target.DOColor(_color, 0.3f);
			}
			transform.DOScale(Vector3.one * (1f + (float)(index + 1) * 0.1f), 0.2f).SetEase(Ease.InOutSine).SetLoops(2, LoopType.Yoyo);
			rewardText.text = GameManager.STAR_REWARD_TABLE[index].ToString();
		}
	}
}
